<?php
	session_start();

	viewPhotos();

	function viewPhotos(){
		$album = $_GET['album'];
		$userName = $_SESSION['userName'];

		$userDir = "../users/".$userName;
		$albumDir = "../users/".$userName."/".$album;

		// Create images array
		$response = array(
			"success" => false,
			"images" => array(),
			"albumTitle" => $album
		);

		// Make sure requesting user exists
		if(is_dir($userDir)){
			console.log("here");
			// Make sure requested album exists
			if($handle = opendir($albumDir)){
				// While the is another file in the directory lo ok at, look at it
				while( false !== ($entry = readdir($handle))){
					$file = $albumDir."/".$entry;
					// Make sure that this is a file and not a directory
					if(is_file($file) && $entry != ".DS_Store"){
						// Add the images to the response object for javascript to use
						array_push($response["images"], "./users/".$userName."/".$album."/".$entry);
						$response["success"] = true;
					}
				}
			}
		}

		echo json_encode($response);
	}
?>
